//
// See the file COPYING for redistribution information.
//

#include <iostream>
#include <stdint.h>
#include <Naipax.hpp>

using namespace std;
using namespace Naipax;

int main() {
    cerr << "Test for the Cache module" << endl;

    try {
        Cache NumCache(4, 1);
        for (uint32_t i = 0; i < 12000; ++i) {
            cout << "Adding " << i << " into cache ... ";

            char Key[16];
            snprintf(Key, 16, "%u", i);

            char Value[2];
            Value[0] = Key[0];
            Value[1] = '\0';

            cout << NumCache.Set(Key, strlen(Key), Value, 1) << endl;
        }

        for (uint32_t i = 0; i < 20000; ++i) {
            cout << "Getting " << i << " from cache ... ";

            char Key[16];
            snprintf(Key, 16, "%u", i);

            char Value[2];
            uint32_t ValueLen = 0;

            cout << NumCache.Has(Key, strlen(Key));
            NumCache.Get(Key, strlen(Key), Value, &ValueLen);
            Value[ValueLen] = '\0';
            cout << ", Value => " << Value << endl;
        }
    }
    catch (Naipax::Error &E) {
        NAIPAX_PERROR(E.What());
        return -1;
    }

    return 0;
}
